import { Account, Settings } from "store/Settings";

declare const dialog: Qml.Dialog;
declare const tokenField: Qml.TextField;
declare const showWebView: Qml.MenuItem;

function handleReady() {

    console.log("NewAccountpage handleReady")

    //@ts-ignore
    console.log("w1 " + typeof dialog)
    //@ts-ignore
    console.log("w2 " + typeof tokenField)
    //@ts-ignore
    console.log("w3 " + typeof showWebView)
    //@ts-ignore
    console.log("w4 " + typeof tokenField2)

    dialog.accepted.connect(() => {
        const accounts: Account[] = [
            ...Settings.get("accounts"),
            { id: new Date().getTime(), token: tokenField.text, isDefault: false }
        ];
        
        Settings.set("accounts", accounts);
    });

    showWebView.clicked.connect(() => {
        const dialog = window.pageStack.push("./LoginDiscord.qml") as Qml.Dialog;


        dialog.accepted.connect(function() {

            //@ts-ignore
            if (window.client.__TOKEN) {
                //@ts-ignore
                console.log("tokenField2.text= " + window.client.__TOKEN)
                //@ts-ignore
                tokenField.text = window.client.__TOKEN
            }
        });
    });
}

function handleDestroy() {
    console.log("NewAccountpage handleDestroy")

}